namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0021 : DbMigration
    {
        public override void Up()
        {
            //RenameTable(name: "dbo.FimReceive", newName: "fim_receives");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiveId", newName: "receive_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "BgSourceId", newName: "bgm_source_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "WorkAreaId", newName: "work_area_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "BgYear", newName: "bgm_year");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiveTypeId", newName: "receive_type_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiptNo", newName: "receipt_no");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiveDate", newName: "receive_date");
            //RenameColumn(table: "dbo.fim_receives", name: "ManualReceipt", newName: "manual_receipt");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiveMode", newName: "receive_mode");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceiveMethodId", newName: "method_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "ChequeNo", newName: "cheque_no");
            //RenameColumn(table: "dbo.fim_receives", name: "BranchId", newName: "branch_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "BankAccId", newName: "bank_acc_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "ContactId", newName: "contact_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "EmpId", newName: "emp_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "TempContact", newName: "temp_contact");
            //RenameColumn(table: "dbo.fim_receives", name: "ReceivedBy", newName: "received_by");
            //RenameColumn(table: "dbo.fim_receives", name: "BidderId", newName: "icm_bid_rec_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "BidOfferColId", newName: "icm_bid_off_col_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PoColId", newName: "icm_po_con_col_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PrePayColId", newName: "icm_po_pre_col_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "DnPenId", newName: "icm_dn_pen_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PoInstalId", newName: "icm_po_instal_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "TranGrpId", newName: "tran_grp_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "TransferId", newName: "deposit_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PetitionId", newName: "petition_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PayReqId", newName: "money_req_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "PayId", newName: "pay_seq");
            //RenameColumn(table: "dbo.fim_receives", name: "RecordStatus", newName: "record_status");
            //RenameColumn(table: "dbo.fim_receives", name: "CreatedBy", newName: "created_by");
            //RenameColumn(table: "dbo.fim_receives", name: "CreatedWhen", newName: "created_when");
            //RenameColumn(table: "dbo.fim_receives", name: "UpdatedBy", newName: "updated_by");
            //RenameColumn(table: "dbo.fim_receives", name: "UpdatedWhen", newName: "updated_when");
            CreateTable(
                "dbo.IcmAssetDepreciation",
                c => new
                    {
                        AssetDepId = c.Int(nullable: false, identity: true),
                        AssetId = c.Int(nullable: false),
                        CalculatedDate = c.DateTime(nullable: false),
                        DepAmount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        TranGrpId = c.Int(),
                        RecordStatus = c.String(maxLength: 2),
                        CreatedBy = c.Int(nullable: false),
                        CreatedWhen = c.DateTime(nullable: false),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.AssetDepId)
                .ForeignKey("dbo.IcmAsset", t => t.AssetId, cascadeDelete: true)
                .ForeignKey("dbo.AcmTransectionGroup", t => t.TranGrpId)
                .Index(t => t.AssetId)
                .Index(t => t.TranGrpId);
            
            AddColumn("dbo.IcmAsset", "LifeYear", c => c.Int());
            //AlterColumn("dbo.FimPetitionDtl", "PetitionId", c => c.Int());
            //AlterColumn("dbo.FimPetition", "PetitionId", c => c.Int(nullable: false, identity: true));
            //AlterColumn("dbo.FimPay", "PetitionId", c => c.Int());
            //AlterColumn("dbo.fim_receives", "amount", c => c.Decimal(precision: 18, scale: 2));
            //AlterColumn("dbo.fim_receives", "remarks", c => c.String());
            AlterColumn("dbo.HrmPsRoyalItemControl", "CtrlId", c => c.Int(nullable: false, identity: true));
            DropTable("dbo.AcmMasAccounts");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.AcmMasAccounts",
                c => new
                    {
                        GlAccId = c.Long(nullable: false, identity: true),
                        GlAccId2 = c.String(),
                        GlAccName = c.String(),
                        GlUpperAccId = c.Int(),
                        RecordStatus = c.String(),
                    })
                .PrimaryKey(t => t.GlAccId);
            
            DropIndex("dbo.IcmAssetDepreciation", new[] { "TranGrpId" });
            DropIndex("dbo.IcmAssetDepreciation", new[] { "AssetId" });
            DropForeignKey("dbo.IcmAssetDepreciation", "TranGrpId", "dbo.AcmTransectionGroup");
            DropForeignKey("dbo.IcmAssetDepreciation", "AssetId", "dbo.IcmAsset");
            AlterColumn("dbo.HrmPsRoyalItemControl", "CtrlId", c => c.Long(nullable: false, identity: true));
            AlterColumn("dbo.fim_receives", "Remarks", c => c.String());
            AlterColumn("dbo.fim_receives", "Amount", c => c.Decimal(precision: 18, scale: 2));
            AlterColumn("dbo.FimPay", "PetitionId", c => c.Long());
            AlterColumn("dbo.FimPetition", "PetitionId", c => c.Long(nullable: false, identity: true));
            AlterColumn("dbo.FimPetitionDtl", "PetitionId", c => c.Long());
            DropColumn("dbo.IcmAsset", "LifeYear");
            DropTable("dbo.IcmAssetDepreciation");
            RenameColumn(table: "dbo.fim_receives", name: "updated_when", newName: "UpdatedWhen");
            RenameColumn(table: "dbo.fim_receives", name: "updated_by", newName: "UpdatedBy");
            RenameColumn(table: "dbo.fim_receives", name: "created_when", newName: "CreatedWhen");
            RenameColumn(table: "dbo.fim_receives", name: "created_by", newName: "CreatedBy");
            RenameColumn(table: "dbo.fim_receives", name: "record_status", newName: "RecordStatus");
            RenameColumn(table: "dbo.fim_receives", name: "pay_seq", newName: "PayId");
            RenameColumn(table: "dbo.fim_receives", name: "money_req_seq", newName: "PayReqId");
            RenameColumn(table: "dbo.fim_receives", name: "petition_seq", newName: "PetitionId");
            RenameColumn(table: "dbo.fim_receives", name: "deposit_seq", newName: "TransferId");
            RenameColumn(table: "dbo.fim_receives", name: "tran_grp_seq", newName: "TranGrpId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_po_instal_seq", newName: "PoInstalId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_dn_pen_seq", newName: "DnPenId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_po_pre_col_seq", newName: "PrePayColId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_po_con_col_seq", newName: "PoColId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_bid_off_col_seq", newName: "BidOfferColId");
            RenameColumn(table: "dbo.fim_receives", name: "icm_bid_rec_seq", newName: "BidderId");
            RenameColumn(table: "dbo.fim_receives", name: "received_by", newName: "ReceivedBy");
            RenameColumn(table: "dbo.fim_receives", name: "temp_contact", newName: "TempContact");
            RenameColumn(table: "dbo.fim_receives", name: "emp_seq", newName: "EmpId");
            RenameColumn(table: "dbo.fim_receives", name: "contact_seq", newName: "ContactId");
            RenameColumn(table: "dbo.fim_receives", name: "bank_acc_seq", newName: "BankAccId");
            RenameColumn(table: "dbo.fim_receives", name: "branch_seq", newName: "BranchId");
            RenameColumn(table: "dbo.fim_receives", name: "cheque_no", newName: "ChequeNo");
            RenameColumn(table: "dbo.fim_receives", name: "method_seq", newName: "ReceiveMethodId");
            RenameColumn(table: "dbo.fim_receives", name: "receive_mode", newName: "ReceiveMode");
            RenameColumn(table: "dbo.fim_receives", name: "manual_receipt", newName: "ManualReceipt");
            RenameColumn(table: "dbo.fim_receives", name: "receive_date", newName: "ReceiveDate");
            RenameColumn(table: "dbo.fim_receives", name: "receipt_no", newName: "ReceiptNo");
            RenameColumn(table: "dbo.fim_receives", name: "receive_type_seq", newName: "ReceiveTypeId");
            RenameColumn(table: "dbo.fim_receives", name: "bgm_year", newName: "BgYear");
            RenameColumn(table: "dbo.fim_receives", name: "work_area_seq", newName: "WorkAreaId");
            RenameColumn(table: "dbo.fim_receives", name: "bgm_source_seq", newName: "BgSourceId");
            RenameColumn(table: "dbo.fim_receives", name: "receive_seq", newName: "ReceiveId");
            RenameTable(name: "dbo.fim_receives", newName: "FimReceive");
        }
    }
}
